import { getToken } from '@/common/auth'
import Api_url from '@/common/config'
export function get(url, params,title) {
  return new Promise((resolve, reject) => {
	uni.showLoading({
		title: title||"加载中"
	});
    uni.request({
		header:{'Authorization':getToken()},
		url:Api_url+url,
		data:params,
		method:"GET",
		success:(res)=>{
			if(res.statusCode==200){
				resolve(res.data)
			}else{
				reject(res)
			}
		},
		fail:(err)=>{
			uni.showModal({
				title:"错误",
				content:"服务器错误维护 或 检查网络！"
			})
			reject(err)
		},
		complete:()=>{
			uni.hideLoading()
		}
	})
  })
}

export function post(url, params,title,type) {
  return new Promise((resolve, reject) => {
	  uni.showLoading({
	  	title: title||"加载中"
	  });
    uni.request({
    	header:{'Authorization':getToken(),'Content-Type' :type=='json'?'application/json;charset=UTF-8':'application/x-www-form-urlencoded;charset=UTF-8'},
    	url:Api_url+url,
		data:params,
    	method:"POST",
    	success:(res)=>{
			if(res.statusCode==200){
				resolve(res.data)
			}else{
				reject(res)
			}
    	},
    	fail:(err)=>{
			uni.showModal({
				title:"错误",
				content:"服务器错误维护 或 检查网络！"
			})
    		reject(err)
    	},
		complete:()=>{
			uni.hideLoading()
		}
    })
  })
}

export default get
